package com.link4a.doms.dao.handler;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.link4a.doms.dao.Page;
import com.link4a.doms.dao.SqlSessionTemplateSupport;
import com.link4a.doms.model.Driver;
import com.link4a.doms.vo.DriverCondition;

@Repository
public class DriverHandler extends SqlSessionTemplateSupport {
	public Driver findById(int id) {
		return getSqlSession().selectOne("findById", id);
	}
	
	public Page<Driver> findPage(DriverCondition condition) {
		return findPage(condition, "countPage", "findPage");
	}
	
	public void merge(Driver driver) {
		getSqlSession().insert("merge", driver);
	}
	
	public void delete(int id) {
		getSqlSession().delete("delete", id);
	}

	public boolean isNameDuplicated(Driver driver) {
		return getSqlSession().selectOne("findByNameAndProvider", driver) != null;
	}
	
	public List<Driver> findByProvider(int ProviderId) {
		return getSqlSession().selectList("findByProvider", ProviderId);
	}
	
	public List<Driver> listByKeyword(String keyword) {
		return getSqlSession().selectList("listByKeyword", "%"+keyword+"%");
	}
}